package br.com.agregador.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Funcoes {	
	
	public Date formataData(String dataString){
		SimpleDateFormat sdFormat = null;		
		sdFormat = new SimpleDateFormat("dd/MM/yy");			
		Date data = null;
		try {
			data = sdFormat.parse(dataString);
		} catch (ParseException e) {			
			return null;
		}
		return data;
	}
	
	public String dateToString(Date data){
		SimpleDateFormat format = new SimpleDateFormat("dd/MM/yy");
		String dt = format.format(data);		
		return dt;
	}
	
	public Date getDataHora(){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		return calendar.getTime();
	}
	
	public String getDataFormatada(Date date){	
		SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
		String dt = format.format(date);		
		return dt;
	}	
	
	public String colocarTraco(String str){			
		String formatada = str;		
		if(str.length() == 10){
			formatada = "("+str.substring(0,str.length()-8)+")";
			formatada += str.substring(2,str.length()-4);
			formatada +="-"+str.substring(6,str.length());
		}	
		return formatada;
	}	
}
